package com.lwlk.util.bit;

import java.util.List;

public class ByteArrayUtil {

    public static byte[] concat(byte[] a, byte[] b) {

        if(a == null) return b;

        if(b == null) return a;

        byte[] tmp = new byte[a.length + b.length];

        System.arraycopy(a, 0, tmp, 0, a.length);

        System.arraycopy(b, 0, tmp, a.length, b.length);

        return tmp;
    }

    public static byte[] concat(byte[] a, byte[] ... bs) {

        byte[] tmp = a;

        for(byte[] ba : bs) tmp = concat(tmp, ba);

        return tmp;
    }

    public static byte[] contract(List<byte[]> params) {

        byte[] tmp = new byte[0];

        for(byte[] param : params) concat(tmp, param);

        return tmp;
    }

    public static byte[] unBoxed(Byte[] bs) {

        byte[] tmp = new byte[bs.length];

        for(int i = 0; i < tmp.length; ++i) tmp[i] = bs[i];

        return tmp;
    }
}